package user_api

import (
	"github.com/gogf/gf/frame/g"
)

// 方法模块
const (
	OPEN_API_METHOD_NAME_LIST             = "user.method.list"
	OPEN_API_METHOD_NAME_CREATE           = "user.method.create"
	OPEN_API_METHOD_NAME_UPDATE           = "user.method.update"
	OPEN_API_METHOD_NAME_DELETE           = "user.method.delete"
	OPEN_API_METHOD_NAME_CREATE_OR_UPDATE = "user.method.save"
)

// 获取方法列表
func GetMethodList(params map[string]interface{}) string {
	return CallApi(OPEN_API_METHOD_NAME_LIST, params)
}

// 创建方法
func CreateMethod(params map[string]interface{}) string {
	return CallApi(OPEN_API_METHOD_NAME_CREATE, g.Map{
		"name":   params["name"],
		"code":   params["code"],
		"system": params["system"],
		"verb":   params["verb"],
	})
}

// 编辑方法
func UpdateMethod(id string, params map[string]interface{}) string {
	return CallApi(OPEN_API_METHOD_NAME_UPDATE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
		"name":   params["name"],
		"code":   params["code"],
		"system": params["system"],
		"verb":   params["verb"],
	})
}

// 删除方法
func DeleteMethod(id string) string {
	return CallApi(OPEN_API_METHOD_NAME_DELETE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
	})
}

// 创建或更新方法
func CreateOrUpdateMethod(id string, params map[string]interface{}) string {
	return CallApi(OPEN_API_METHOD_NAME_CREATE_OR_UPDATE, g.Map{
		"api_uri_placeholder_values": g.Map{
			"id": id,
		},
		"name":   params["name"],
		"code":   params["code"],
		"system": params["system"],
		"verb":   params["verb"],
	})
}